package com.wuyangnju.healthclub.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.wuyangnju.healthclub.entity.Person;
import com.wuyangnju.healthclub.service.StatisticService;

@Controller
public class StatisticController {

	@Resource
	StatisticService statisticService;

	@RequestMapping(value = { "/statistic.do" })
	public ModelAndView singlePersonRegister(@RequestParam String date
	// @RequestParam int year,@RequestParam int month, @RequestParam int day
	) {
		String[] tmp = date.split("/");
		int month = Integer.parseInt(tmp[0]);
		int day = Integer.parseInt(tmp[1]);
		int year = Integer.parseInt(tmp[2]);

		List<Person> persons = statisticService.getAllPerson();
		ArrayList<Long> ageInfo = statisticService.getAgeInfo();
		ArrayList<Long> sexInfo = statisticService.getSexInfo();
		ArrayList<Long> statusInfo = statisticService.getStatusInfo();

		ModelAndView modelAndView = new ModelAndView("statistic");
		modelAndView.addObject("persons", persons);
		modelAndView.addObject("ageInfo", ageInfo);
		modelAndView.addObject("sexInfo", sexInfo);
		modelAndView.addObject("statusInfo", statusInfo);
		modelAndView.addObject("year", year);
		modelAndView.addObject("month", month);
		modelAndView.addObject("day", day);
		modelAndView.addObject("daySum", statisticService.getDaySumOfPerson(
				year, month, day));
		modelAndView.addObject("monthSum", statisticService
				.getMonthSumOfPerson(year, month));
		modelAndView.addObject("nextDaySum", statisticService
				.getNextDaySumOfPerson());
		modelAndView.addObject("nextMonthSum", statisticService
				.getNextMonthSumOfPerson());
		return modelAndView;
	}
}